#!/bin/bash

# 检查参数数量
if [ "\$1" = "" ]; then
    echo "用法: \$0 <平台> [架构]"
    exit 1
fi

PLATFORM=\$1
ARCH=\$2

# 设置默认架构为amd64，如果未指定架构参数的话
if [ -z "$ARCH" ]; then
    ARCH=amd64
fi
# 创建输出文件夹（如果不存在）
mkdir -p out
# 设置Go编译参数


# 根据平台和架构生成可执行文件
if [ "$PLATFORM" = "linux" ]; then
    export CGO_ENABLED=0
    export GOOS=linux
    if [ "$ARCH" = "amd64" ]; then
        export GOARCH=amd64
    elif [ "$ARCH" = "arm64" ]; then
        export GOARCH=arm64
    else
        echo "不支持的架构：$ARCH"
        exit 1
    fi
    go build -o out/app_linux_$ARCH main.go
elif [ "$PLATFORM" = "windows" ]; then
    export CGO_ENABLED=1
    export GOOS=windows
    if [ "$ARCH" = "amd64" ]; then
        export GOARCH=amd64
    else
        echo "不支持的架构：$ARCH"
        exit 1
    fi
    go build -o out/app_windows_$ARCH.exe main.go
else
    echo "不支持的平台：$PLATFORM"
    exit 1
fi

echo "打包完成：$PLATFORM $ARCH"
